package classLoader;

import classLoader.MyClassLoader;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * 热部署
 */

/**
 * cd D:\gitee\mavenProject\src\main\java\classLoader
 * javac HotDeploymentDemo.java
 */
public class HotDeployment {

    public static void main(String[] args) {

        while (true) {
            try {
                // class文件路径为：D:\gitee\mavenProject\src\main\java\classLoader\HotDeploymentDemo.class
                MyClassLoader myClassLoader = new MyClassLoader("D:\\gitee\\mavenProject\\src\\main\\java\\classLoader\\");
                Class clazz = myClassLoader.findClass("HotDeploymentDemo");
                Object obj = clazz.newInstance();
                Method method = clazz.getMethod("fun");
                method.invoke(obj);

                Thread.sleep(5000);

            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            } catch (InstantiationException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (NoSuchMethodException e) {
                e.printStackTrace();
            } catch (InvocationTargetException e) {
                e.printStackTrace();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

    }

}
